﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Rotempco.ORM.Generator.Enums;
using Rotempco.ORM.Generator.Objects;

namespace Rotempco.ORM.Generator.Logic
{
    public class FileNameLogic
    {
        public static string GetClassFileName(string className, TemplateEnum templateEnum)
        {
            switch (templateEnum)
            {
                case TemplateEnum.ADALCodebehind:
                    return className + "Data.ORM.cs";
                case TemplateEnum.DAL:
                    return className + "Data.cs";
                case TemplateEnum.EntityObject:
                    return className + ".cs";
                case TemplateEnum.PropertyEntityObject:
                    return className + ".cs";
                case TemplateEnum.Factory:
                    return "Factory.cs";
                case TemplateEnum.DataFactory:
                    return "DataFactory.cs";
            }

            throw new Exception("Template: " + templateEnum + " not implemented yet !");
        }

        public static string GetFilePath(RotempcoSettings projectSettings, string className, TemplateEnum templateEnum)
        {
            switch (templateEnum)
            {
                case TemplateEnum.ADALCodebehind:
                    return projectSettings.GetValue("@DALImplementationPath") + GetClassFileName(className, templateEnum);
                case TemplateEnum.DAL:
                    return projectSettings.GetValue("@DALImplementationPath") + GetClassFileName(className, templateEnum);
                case TemplateEnum.EntityObject:
                    return projectSettings.GetValue("@EntityObjectPath") + GetClassFileName(className, templateEnum);
                case TemplateEnum.PropertyEntityObject:
                    return projectSettings.GetValue("@PropertyEntityObject") + GetClassFileName(className, templateEnum);
                case TemplateEnum.Factory:
                    return projectSettings.GetValue("@FactoryPath") + GetClassFileName(className, templateEnum);
                case TemplateEnum.DataFactory:
                    return projectSettings.GetValue("@FactoryPath") + GetClassFileName(className, templateEnum);
            }

            throw new Exception("Template: " + templateEnum + " not implemented yet !");
        }

        public static string GetProjectNamespace(RotempcoSettings projectSettings)
        {
            string mainProjectFile = projectSettings.GetValue("@MainProjectFile");
            int index = mainProjectFile.LastIndexOf('\\') + 1;
            string projectNamespace = mainProjectFile.Substring(index, mainProjectFile.LastIndexOf('.') - index);
            return projectNamespace;
        }
    }
}
